package com.controller;

import com.entity.User;
import com.github.pagehelper.PageInfo;
import com.service.BackModifyService;
import com.util.AjaxResult;
import com.util.StringUtil;
import com.vo.PageVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView;

import javax.jws.soap.SOAPBinding;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import java.util.Map;

@RestController
public class ModifyController {

@Autowired
    BackModifyService backModifyService;


//登录后台修改页面
    @RequestMapping("/show_back_home.do")
    public ModelAndView backHome(HttpSession session, Map map){
//        AjaxResult ajaxResult = new AjaxResult();
//        ajaxResult.setSuccess(true);
        User user = (User)session.getAttribute("user");
        map.put("nickname",user.getNickname());
        ModelAndView modelAndView = new ModelAndView();
        modelAndView.setViewName("/background/back_Home");
        return modelAndView;
    }



   // 后台查找所有用户
    @RequestMapping("/user/findBackUser.do")
    public PageInfo<User> findBackUser(String pageNo, PageVo pageVo){
        System.out.println(pageVo);
        PageInfo<User> allPage = backModifyService.selAllPage(StringUtil.getInt(pageNo), pageVo);
        return allPage;
    }

    //后台修改用户用户信息
    @RequestMapping("/user/showBackUser.do")
    public AjaxResult showBackUser(String id){
        AjaxResult ajaxResult = new AjaxResult(true, "查询成功", null);
        User userById = backModifyService.selUserById(StringUtil.getInt(id));
        ajaxResult.setObj(userById);
        return ajaxResult;
    }

    //修改用户状态
    @RequestMapping("/user/modifyBackUser.do")
    public AjaxResult modifyBackUser(User user){
        backModifyService.updateUserInfoS(user);
        return new AjaxResult(true,"修改成功",null);
    }
}
